#ifndef _ICAR_PKG_H
#define _ICAR_PKG_H

#if defined(__cplusplus)
extern "C" {
#endif

#include <stdint.h>
#include <sys/uio.h>

#define SUBPACKAGE	0x2000
#define ENCRYPT(p)	(((p) & 0x7) << 10)
#define ENCRYPT_WAY(p)	(((p) >> 10) & 0x7)

#define ENCRYPT_RSA		1
#define ENCRYPT_NONE	0

#define MSG_LENGTH(p)	((p) & 0x3ff)
#define MAX_PKG_CNT		0xffff

struct iovector {
	uint8_t *iov_base;
	size_t iov_len;
};

struct icar_iovec{
	int total;
	struct iovector v[0];
};

void icar_pkg_print(uint8_t *src, size_t size);
void icar_print_iovec(struct icar_iovec *);
uint8_t icar_data_auth(uint8_t *src, size_t size);

int icar_pkg_trans_add_head_tail(uint8_t *dest, uint8_t *src, size_t size);

int icar_pkg_del_head_tail(uint8_t *dest, uint8_t *src, size_t size);

int icar_bcd(uint8_t *bcd, const char *number, size_t size); /** Brief: 将电话号码转换为BCD码 */

struct icar_iovec *icar_pkg_iovec(uint16_t id, const char *number, uint8_t *message, size_t size);

struct icar_iovec* icar_malloc_iovec(int nmemb, size_t size);

void free_iovec(struct icar_iovec *);

#if defined(__cplusplus)
}
#endif

#endif
